//
import { http } from '@/utils/http'
import {
  OrderInfomation,
  ShopComment,
  ShopConfirmOrder,
  ShopOrderItem,
  ShopOrderResponse,
  ShopResponse,
} from './shop.type'
export interface ResponsePage {
  code: number
  data: DataItem
  page: number
  pageSize: number
  totalCount: number
  totalPage: number
}
interface DataItem {
  list: ShopCar[]
}
export interface ShopCar {
  id: number
  user_id: number
  good_id: number
  num: number
  create_time: string
  update_time: string
}
export interface GoodShopCar {
  id: string | number
  num: string | number
  type: string | number
}

/** 获取首页数据 */
export const getShopCarList = () => {
  return http.post<ResponsePage>('good/carts', {})
}
// 获取浏览记录 /user/visitRecord
export const getVisitRecord = () => {
  return http.post<ShopResponse>('user/visitRecord', {})
}
// 获取商品详情 /good/detail
export const getGoodDetail = (id: number | string) => {
  return http.post('good/detail', { id })
}
// 获取商品评价列表 /good/comments
export const getGoodComments = (data: ShopComment) => {
  return http.post('good/comments', data)
}
// 获取秒杀商品详情 /good/flushGoodDetail
export const flushGoodDetail = (id: number | string) => {
  return http.post('good/flushGoodDetail', { id })
}
// 添加购物车 /good/cartEdit
export const addShopCar = (data: GoodShopCar) => {
  return http.post('good/cartEdit', data)
}
// 设置是否收藏 /good/collectEdit
export const setCollectEdit = (data: { id: number | string; type: number | string }) => {
  return http.post('good/collectEdit', data)
}
// 获取订单 /order/confirm
export const getOrderConfirm = (data: ShopConfirmOrder) => {
  return http.post('order/confirm', data)
}
// 创建订单 /order/create
export const createOrder = (data: OrderInfomation) => {
  return http.post('order/create', data)
}
// 发起支付 /order/pay
export const orderPay = (data: { id: number | string }) => {
  return http.post('order/pay', data)
}
// 分类配置 /cateConfig
export const getCateConfig = () => {
  return http.post('cateConfig', {})
}
// 获取商品分类 /good/list
export const getGoodList = (data: ShopOrderResponse) => {
  return http.post('good/list', data)
}
// 获取优惠卷  /activity/coupons
export const getCoupons = () => {
  return http.post('activity/coupons', {})
}
// 领取优惠卷 /activity/couponReceive
export const couponReceive = (data: { id: number | string }) => {
  return http.post('activity/couponReceive', data)
}
// 上报浏览记录 /user/addVisitRecord
export const addVisitRecord = (data: { id: number | string }) => {
  return http.post('user/addVisitRecord', data)
}
// 生成二维码 /good/qrcode
export const createQrCode = (data: ShopOrderItem) => {
  return http.post('good/qrcode', data)
}
